from django.http import JsonResponse


# 获取验证结果
def RulesValidate(request,method,rules):
    try:
        data = {}
        if method == 'POST' or method == 'post':
            data = request.POST.dict()
        else:
            data = request.GET.dict()
        # 验证数据
        for key,values in rules.items():
            item = data.get(key,None)
            if item == None:
                return JsonResponse({'msg': f'{values}:{key}不能为空', 'code': 403})
        return None
    except Exception as e:
        return None